var cont=1;
var pageSize=5;
var pages=0;
var gender=0;
var lasetime="";
var time=Date.parse(new Date())/1000;
function getuser() {
    $.ajax({
        type : "GET",
        url : getRequestUrl("/user/get"),
        data:{
            timestamp:time,
            gender:gender,
            page_num:cont,
            page_size:pageSize,
            last_active_time:lasetime
        },
        success : function(datas) {
            console.log(datas);
            var arr=datas.response_params.result;
            pages=datas.response_params.total_cnt;
            var strs="";
            $.each(arr,function (i,el) {
                var arr2=el.auth_info;
                var strs2="";
                $.each(arr2,function (j,v) {
                    if(v.auth_type==2&&v.status==2){
                        strs2+=`<i class="icon-user icon-2x"></i>`
                    }else  if(v.auth_type==3&&v.status==2){
                        strs2+=`<i class="icon-mobile-phone icon-3x"></i>`
                    }else  if(v.auth_type==1&&v.status==2){
                        strs2+=`<i class="icon-file icon-2x"></i>`
                    }else  if(v.auth_type==4&&v.status==2){
                        strs2+=` <i class="icon-briefcase"></i>`
                    }else  if(v.auth_type==5&&v.status==2||v.auth_type==6&&v.status==2){
                        strs2+=`<i class="icon-credit-card"></i>`
                    }
                });
                strs+=`<li>
                            <div class="figures-box" style="margin:0" data-id=`+arr[i].user_id+` onclick="getuseInfo(this)">
                                <div class="figures-massage">
                                    <div class="img-box">
                                        <img src=`+arr[i].portrait+`>
                                    </div>
                                    <div class="title-box">
                                        <h2>`+arr[i].nick_name+`</h2>
                                        <span class="xbicon `+sex(el.gender)+`"></span>
                                       `+strs2+`
                                        <p class="xx"><span>`+arr[i].age+`岁/`+arr[i].industry+`</span></p>
                                    </div>
                                </div>
                                <div class="img-list">`+getimg(arr[i].show_pics)+`</div>
                                <div class="introduce-box">
                                    <p class="c999">`+arr[i].profile+`</p>
                                </div>
                                <div class="label">`+getlabel(arr[i].labels)+`<p>来自`+arr[i].company+`</p>
                                </div>
                            </div>
                      
                    </li>`
            });
            $(strs).appendTo("#list");
            hideToast();
            $("#loading").hide();

        },
        error : function(err) {
        	dealCPErrorResponse(err);
        }
    });
}
function sex(s) {
    if(s=="1"){
        return "nan"
    }else {
        return "nv"
    }

}
function getimg(imgarr) {
    var imgs="";
    $.each(imgarr,function (i,el){
        imgs+=`<div class="img" style="background-image: url(`+imgarr[i]+`)"></div>`
    });
    return imgs
}
function getlabel(labelss) {
    var labels="";
    $.each(labelss,function (i,el){
        labels+=`<span>`+labelss[i]+`</span>`
    });
    return labels
}

function gcscroll(obj) {
    var $this =$(obj),
        viewH =$this.height(),//可见高度
        contentH =$this.get(0).scrollHeight,//内容高度
        scrollTop =$this.scrollTop();//滚动高度
    // console.log("可见高度"+viewH);
    // console.log("内容高度"+contentH);
    // console.log("滚动高度"+scrollTop);
    if(contentH - viewH - scrollTop <=1) { //到达底部100px时,加载新内容
       // alert("11111111")

        //console.log(cont);
        var nowpage=pages%pageSize==0?(pages/pageSize):(Math.floor(pages/pageSize)+1);
        if(nowpage===cont){
            return false
        }else {
            cont+=1;
            showToast();
            getuser()
        }

    }
}
function showToast() {
    $("#loadingToast").show()
}
function hideToast() {
    $("#loadingToast").hide();
}
$(function () {
    getuser();
});
$("#ok").on('click',function () {
    gender=$("#sex").val();
    lasetime=$("#hytime").val();
    showToast();
    $("#list").html("");
    getuser();
});
function getuseInfo(obj) {
    var $this=$(obj);
    var id=$this.attr("data-id");
    window.location.href="Personal-information.html?userid="+id;
}